//
//  AudiovisualViewController.m
//  OwnerNews
//
//  Created by lanou3g on 15/8/28.
//  Copyright (c) 2015年 Drawzyn. All rights reserved.
//

#import "AudiovisualViewController.h"
#import "AudiovisualManager.h"
#import "AudioVisualTableViewCell.h"
#import "AvdiovisualModel.h"
#import "UIImage+ImageDownLoader.h"
#import "PlayViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#import "MBProgressHUD+MJ.h"



@interface AudiovisualViewController ()

@property (nonatomic,strong) UITableView * tableView;

@end

@implementation AudiovisualViewController

- (void)viewDidLoad {
    [super viewDidLoad];
 
    _MyTableView = [[MyView alloc]initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 100)];
    [self.view addSubview:_MyTableView];
    _MyTableView.dataSource = self;
    _MyTableView.delegate = self;
    self.navigationItem.title = @"我的视觉";
  //  [self CustomMyselfNavigation];
    UIBarButtonItem *right  = [[UIBarButtonItem alloc]initWithTitle:@"🔁" style:UIBarButtonItemStylePlain target:self action:@selector(buttonAction1)];
    self.navigationItem.rightBarButtonItem = right;
    [[AudiovisualManager defaultManager] GetMyAvDataAndLoadMyTableView:^{
        [self.MyTableView reloadData];
    }];
}

//button点击方法
-(void)buttonAction1{
    [MBProgressHUD showMessage:@"刷新中。。。。。"];
    [[AudiovisualManager defaultManager]GetMyAvDataAndLoadMyTableView:^{
        [self.MyTableView reloadData];
    }];
 
    
    [MBProgressHUD hideHUD];
    [MBProgressHUD showSuccess:@"刷新完成!"];
}

#pragma UITableView Delegate DataSource 的方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [AudiovisualManager defaultManager].AvManAgerData.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    AudioVisualTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AVCID"];
    
    if (cell == nil) {
    cell = [[AudioVisualTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"AVCID"];
     
    }
    
    AvdiovisualModel *AVM = [AudiovisualManager defaultManager].AvManAgerData[indexPath.row];
    cell.MyTitleLabel.text = [NSString stringWithFormat:@"%@:%@",AVM.title,AVM.AVdescription];
    [UIImage downLoaderImageWithURL:AVM.cover andBlock:^(UIImage *image) {
        cell.MimgView.image = image;
    }];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    PlayViewController *PLVC = [[PlayViewController alloc]init];
    PLVC.MyIndexPath = indexPath;
    [self.navigationController presentViewController:PLVC animated:YES completion:^{
        
    }];
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 200;
}

///**
// *  重写self.navigation
// */
//
//- (void)CustomMyselfNavigation {
//    /**
//     对self.navigation的一些操作
//     */
//    _customView = [[TheCustomView alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
//    _customView.MySegment.selectedSegmentIndex = 0;
//    self.navigationItem.titleView = _customView;
//    [_customView.MySegment addTarget:self action:@selector(ChangeViewed) forControlEvents:UIControlEventValueChanged];
//   
////    [self.navigationController.navigationBar setBarTintColor:[UIColor purpleColor]];
//    self.navigationController.navigationBar.alpha = 0.6;
//}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
